# {{ ansible_managed }}
#---------------------------------------------------------------------
# service: {{ service.name }} @ {{ inventory_hostname }}:{{ service.port }}
#---------------------------------------------------------------------
listen {{ service.name }}
    bind {{ service.ip|default('*') }}:{{ service.port }}
    mode {{ service.protocol|default('tcp') }}
    maxconn {{ service.haproxy.maxconn|default(10000) }}
    balance {{ service.haproxy.balance|default('roundrobin') }}
{% if service.options is defined and service.options|length > 0%}
{% for opt in service.options %}
    {{ opt }}
{% endfor %}
{% endif %}
    default-server {{ service.default|default('inter 3s fastinter 1s downinter 5s rise 3 fall 3 on-marked-down shutdown-sessions slowstart 30s maxconn 3000 maxqueue 128 weight 100') }}

    # server
{% for server in service.servers %}
    server {{ server.name }} {{ server.ip }}:{{ server.port }} {% if server.backup is defined and server.backup|bool %}backup{% endif %} {% if server.weight is defined and server.weight|int >=0 and server.weight|int < 256 %}weight {{ server.weight }}{% endif %} {{ server.options|default('') }}
{% endfor %}
